package com.mcr.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcr.reggie.common.R;
import com.mcr.reggie.dto.OrdersDto;
import com.mcr.reggie.entity.Orders;
import com.mcr.reggie.service.OrdersService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    /**
     *
     *
     *
     *
     * * * * * * * * * * * * * * * * * * * *   前台  * * * * * * * * * * * * * * * * * * *
     *
     *
     *
     */
    @ApiOperation(value = "前台用户下单")
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("下单成功！！！");
    }
    @ApiOperation(value = "用户订单展示")
    @GetMapping("/userPage")
    public R<Page<OrdersDto>> getUserPage(Integer page,Integer pageSize){
        Page<OrdersDto> ordersPage=ordersService.getNewOrder(page,pageSize);
        return R.success(ordersPage);
    }
    @ApiOperation(value = "用户再来一单")
    @PostMapping("/again")
    public R<String> submitAgain(@RequestBody Orders orders){
        ordersService.submitAgain(orders.getId());
        return R.success("购物车装填完成");
    }
    /**
     *
     *
     *
     *
     ******************************************** 后台 ************************************
     *
     *
     *
     *
     */
    @ApiOperation(value = "后端员工查看订单")
    @GetMapping("/page")
    public R<Page> page(@RequestParam(value = "page",required = true)Integer page,
                        @RequestParam(value = "pageSize",required = true)Integer pageSize,
                        @RequestParam(value = "number",required = false)String number,
                        @RequestParam(value = "beginTime",required = false)String beginTime,
                        @RequestParam(value = "endTime",required = false)String endTime){
        Page ordersPage = ordersService.getPage(page, pageSize, number, beginTime, endTime);
        return R.success(ordersPage);
    }
    @ApiOperation(value = "修改订单状态")
    @PutMapping
    public R<String> updateStatus(@RequestBody Orders orders){
        ordersService.updateStatus(orders);
        return R.success("订单状态修改成功");
    }
}
